# -*- coding: utf-8 -*-
# @Time    : 2021/5/16 14:29
# @Author  : 夏思毅
# @Email   : 2739124228@qq.com
# @File    : 面向对象作业--回合制游戏.py
# @Software: PyCharm

import random

class People():

    def __init__(self,name,sex,zb):
        """ 初始化"""
        self.name=name
        self.sex=sex
        self.hp=100
        self.zb=zb
    def hit(self,people):
        #攻击
        if people.zb!= None:
            people.hp-=5
            print(f"{self.name}发动攻击,但被{people.name}装备抵挡，{people.name}生命值-5")
            print(f"{self.name}:".ljust(self.hp,"-"))
            print(f"{people.name}:".ljust(people.hp, "-"))
        #     有装备扣5点血
        else:
            people.hp-=10
            print(f"{self.name}发动攻击,{people.name}直接破防，{people.name}生命值-10")
            print(f"{self.name}:".ljust(self.hp, "-"))
            print(f"{people.name}:".ljust(people.hp, "-"))
        #     没装备扣10点血
    def hacker(self):
        #开挂
        self.hp=1000000
        print(f"{self.name}开挂啦！")

    def login(self,name1,sex1,zb1):
        pass



class Room():
    # 初始化
    def __init__(self, name):
        self.name = name
        self.room = []
        if len(self.room) == 2:
            print("房间人数已达上限")

    def joinroom(self, a):
        # 加入房间

        self.room.append(a)
        print(f"{a.name}成功进入{self.name}".center(80, "-"))

# p=People("夏思毅","男","外道魔像")
# z=People("陈柱","男",' ')
# roomchoice=Room("雨隐村")
# roomchoice.joinroom(p)
# roomchoice.joinroom(z)
peoplelist = {}
roomlist = {}
while 1:
    choice=input(
        '''
    创建角色:1
    创建房间:2
    加入房间:3
        '''
    )

    if choice == "1":
        # number=input("序号：")
        name1 = input("姓名：")
        sex1 = input("性别：")
        zb1 = input("装备：")

        peoplelist[name1] = People(name1,sex1,zb1)

    if choice == "2":
        roomname=input("房间名：")
        roomlist[roomname] = Room(roomname)

    if choice == "3":
        print(roomlist)
        roomchoice=input("选择你要加入的房间：")
        if roomchoice in roomlist:
            print(peoplelist)
            for i in range(2):
                peoplechoice=input("选择你要加入该房间的角色")
                roomlist[roomchoice].joinroom(peoplelist[peoplechoice])
            print()
            print("战斗开始".center(80, "*"))
            round=0
            while 1:
                first=random.randint(1,2)
                print(f"Round{round}".center(80,"+"))
                round+=1
                if first==1:
                    (roomlist[roomchoice].room[0]).hit(roomlist[roomchoice].room[1])

                else:
                    (roomlist[roomchoice].room[1]).hit(roomlist[roomchoice].room[0])

                if (roomlist[roomchoice].room[0]).hp==0 :
                    print(f"{(roomlist[roomchoice].room[0]).name}已被击败，胜者为{(roomlist[roomchoice].room[1]).name}")
                    exit()
                elif (roomlist[roomchoice].room[1]).hp==0:
                    print(f"{(roomlist[roomchoice].room[1]).name}已被击败，胜者为{(roomlist[roomchoice].room[0]).name}")
                    exit()

